package com.zombie.ui;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.math.Interpolation;
import com.badlogic.gdx.scenes.scene2d.Actor;
import com.badlogic.gdx.scenes.scene2d.Event;
import com.badlogic.gdx.scenes.scene2d.EventListener;
import com.badlogic.gdx.scenes.scene2d.InputEvent;
import com.badlogic.gdx.scenes.scene2d.Stage;
import com.badlogic.gdx.scenes.scene2d.actions.ScaleByAction;
import com.badlogic.gdx.scenes.scene2d.ui.Button;
import com.badlogic.gdx.scenes.scene2d.ui.Label;
import com.badlogic.gdx.scenes.scene2d.ui.Skin;
import com.badlogic.gdx.scenes.scene2d.ui.TextButton;
import com.badlogic.gdx.scenes.scene2d.utils.ChangeListener.ChangeEvent;
import com.zombie.Constants;
import com.zombie.ZombieGame;
import com.zombie.logic.core.ZombieWorld;
import com.zombie.util.state.transition.FadeInTransition;
import com.zombie.util.state.transition.FadeOutTransition;

public class MenuUI extends UI implements EventListener{

	public Label fpsLabel;
	public Label errorLabel;
	public Button start,load,options,exit;
//	public TextField passwordTextField;
//	public TextField loginTextField;
//	public Window window;
	public Actor current;
	
	public void init(){
		skin = new Skin(Gdx.files.internal("data/ui/uiskin.json"));

		start = new TextButton("Start", skin);
		start.setColor(Color.RED);
		start.setBounds(32, 150, 64, 24);
		start.addListener(this);
		load = new TextButton("Load", skin);
		load.setColor(Color.RED);
		load.setBounds(32+64+32, 150, 64, 24);
		load.addListener(this);
		
		options = new TextButton("Options", skin);
		options.setColor(Color.RED);
		options.setBounds(32+64+32+64+32, 150, 64, 24);
		options.addListener(this);

		exit = new TextButton("Exit", skin);
		exit.setColor(Color.RED);
		exit.setBounds(32+64+32+64+32+64+32, 150, 64, 24);
		exit.addListener(this);
//		Label passwordLabel = new Label("Password: ", skin);
//		passwordTextField = new TextField("", skin);
//		passwordTextField.setMessageText("password");
//		passwordTextField.setPasswordCharacter('*');
//		passwordTextField.setPasswordMode(true);
//
//		Label loginLabel = new Label("Login: ", skin);
//		loginTextField = new TextField("", skin);
//		loginTextField.setMessageText("login");
//
//		errorLabel = new Label("", skin);
//		errorLabel.setColor(Color.RED);
//		window = new Window("Login", skin);
//		window.setPosition(Gdx.graphics.getWidth() / 2 - window.getWidth() / 2,
//				Gdx.graphics.getHeight() / 2 - window.getHeight() / 2);
//		window.setMovable(false);
//		window.defaults().spaceBottom(10);
//		window.defaults().spaceTop(10);
//		window.row().fill().expandX();
//
//		window.row();
//
//		window.add(loginLabel).colspan(2);
//		window.add(loginTextField).minWidth(60).colspan(2);
//		window.row();
//		window.add(passwordLabel).colspan(2);
//		window.add(passwordTextField).minWidth(60).colspan(2);
//		window.row();
//		window.add(errorLabel).colspan(4).expandY();
//		window.row();
//		window.add(button).colspan(4);
//
//		window.pack();
		
	}

	@Override
	public void add(Stage stage) {
		stage.addActor(start);
		stage.addActor(load);
		stage.addActor(options);
		stage.addActor(exit);
	}

	@Override
	public boolean handle(Event event) {
		if (event instanceof InputEvent){
			current = event.getListenerActor();
			ScaleByAction act = new ScaleByAction();
			act.setAmount(3.3f);
			act.setDuration(22);
			act.setTime(2);
			act.setInterpolation(Interpolation.linear);

			event.getListenerActor().addAction(act);
//			act = new ScaleToAction();
//			act.setScale(1f);
//			act.setDuration(2);
//			event.getListenerActor().addAction(act);
			System.out.println(event + "   " + event.getListenerActor());

		} else if (event instanceof ChangeEvent){
			if (event.getListenerActor() == exit)
				Gdx.app.exit();
			if (event.getListenerActor() == start){
				ZombieWorld.init(0);
				ZombieGame.getInstance().enterState(Constants.STATE_GAME, new FadeOutTransition(Color.RED), new FadeInTransition(Color.RED));
			}
			if (event.getListenerActor() == options){
				ZombieGame.getInstance().enterState(Constants.STATE_OPTIONS, new FadeOutTransition(Color.RED), new FadeInTransition(Color.RED));
			}
		}
		return false;
	}
	
	
}
